//
//  ScenesFOA.cpp
//  ScenesAudioMix
//
//  Created by Branch on 2017/5/10.
//  Copyright © 2017年 branch. All rights reserved.
//

#include "ScenesFOA.h"
#include "ScenesFOA/ScenesFoaMixer.h"


#define REOPEN_ERROR        -1
#define OPEN_ERROR          -2
#define NOOPEN_ERROR        -3
#define PROCESS_ERROR       -4

static ScenesFoaMixer* s_scenesFoaMixer = nullptr;

int scs_openFoaMixer(uint32_t nsamples){
    if (s_scenesFoaMixer) {
        return REOPEN_ERROR;
    }
    
    s_scenesFoaMixer = new ScenesFoaMixer();
    
    if (s_scenesFoaMixer && s_scenesFoaMixer->openMixer(nsamples)) {
        return 0;
    }
    return OPEN_ERROR;
}


void scs_closeFoaMixer(){
    if (s_scenesFoaMixer) {
        s_scenesFoaMixer->closeMixer();
        delete s_scenesFoaMixer;
        s_scenesFoaMixer = nullptr;
    }
}



int scs_processFoaAudio(float* dataW,float* dataY,float* dataZ,float* dataX,
                        float* matrix4,float* dataL,float* dataR){
    if(!s_scenesFoaMixer){
        return NOOPEN_ERROR;
    }

    if(!s_scenesFoaMixer->processAudio(dataW, dataY, dataZ, dataX,
                                      matrix4, dataL, dataR)){
        return PROCESS_ERROR;
    }
    return 0;
}


